#!/bin/bash
#项目名称
PROJECT_NAME="mini-publish"
PROJECT_GIT_URL="git@git.superboss.cc:lvduo/mini-publish-system.git"
GITBRANCH="master"
TOMCAT_PORT="6666"
FINAL_NAME="mini-publish"
#项目根目录
HOME_ROOT="/data/"$PROJECT_NAME
#项目源码
SOURCE_DIR=$HOME_ROOT"/source/"
#项目源码构建目录
PROJECT_DIR=$SOURCE_DIR`ls $SOURCE_DIR`
#tomcat webroot
WEB_ROOT=$HOME_ROOT"/code/"
#tomcat 目录
TOMCAT_HOME=$HOME_ROOT"/tomcat/"
MAVEN_HOME="/data/apache-maven-3.3.9"
update_code(){
        if [ -d $PROJECT_DIR ]
        then
            cd $PROJECT_DIR
            git pull
        else
            cd $SOURCE_DIR
            git clone $PROJECT_GIT_URL  
            cd $PROJECT_DIR
            git checkout $GITBRANCH     
        fi
}
install(){
        cd $PROJECT_DIR;
        $MAVEN_HOME/bin/mvn clean; 
        $MAVEN_HOME/bin/mvn install;
}
 
 
deploy(){
        TEMP=$WEB_ROOT"*"
        rm -fR $TEMP
        TEMP=$PROJECT_DIR"/target/overseas-mini-publish/*"
        cp -fR $TEMP $WEB_ROOT
}
 
restart(){
	tomcat=`jps -v|grep mini-publish|awk  '{print $1}' `
	kill -9 $tomcat
    sleep 5
    bash $TOMCAT_HOME"bin/catalina.sh" start
}

stop(){
    tomcat=`jps -v|grep mini-publish|awk  '{print $1}' `
    kill -9 $tomcat
    sleep 5
}
 
help(){
        echo $"Usage: $0 {update_code|install|backup|deploy|restart}"
}
 
case "$1" in
stop)
        stop
;;
update_code)
        update_code
;;
install)
        install
;;
deploy)
        deploy
;;
restart)
        restart
;;
-h)
        help
;;
--help)
        help
;;
*)
        update_code
        install
        deploy
        restart
;;
 
esac
 
exit 0
